<?php
	defined( '_JEXEC' ) or die( 'Restricted access' );
	jimport( 'joomla.application.component.controller' );
	require_once(JPATH_COMPONENT.DS.'dominio'.DS.'DTOFactory.php');
	
	class ActinMapController extends JController
	{
		function display()
		{
			$document=&JFactory::getDocument();
			
			$viewName="home";
			$viewType=$document->getType();
			
			$view=&$this->getView($viewName,$viewType);
			
			$view->setLayout('default');
			$view->display();
		}

		function getEventComments()
		{
			
		}

		function submitComment()
		{
			
		}

		function getAreaEvents()
		{
			
		}

		function subscribeEvent()
		{
			
		}
		
		function submitEventForm(){
			if(JFactory::getUser()->id){
				$document=&JFactory::getDocument();
				
				$modelEvent=&$this->getModel('event','ModelActinMap');
				
				$viewName="eventCreation";
				$viewType=$document->getType();
				
				$view=&$this->getView($viewName,$viewType);
				
				if(!JError::isError($modelEvent)){
					$view->setModel($modelEvent,true);
				}
				
				$view->setLayout('default');
				$view->display();
			}
			else{
				$this->setRedirect(JRoute::_('index.php?option=com_actinmap'));
			}
		}

		function submitEvent()
		{
			if(JFactory::getUser()->id){
				$modelEvent=&$this->getModel('event','ModelActinMap');
				$factoria=DTOFactory::getInstance();
				$modelEvent->saveEvent($factoria->getDTOEventFromRequest());
			}
			$this->setRedirect(JRoute::_('index.php?option=com_actinmap'));
		}

		function controlPanel()
		{
			$user =& JFactory::getUser();
			if($user->id)
			{
				$document=&JFactory::getDocument();
				
				$modelEvents=&$this->getModel('event','ModelActinMap');
				$viewName="controlPanel";
				$viewType=$document->getType();
				
				$view=&$this->getView($viewName,$viewType);
				
				if(!JError::isError($modelEvents)){
					$view->setModel($modelEvents,true);
				}
				
				$view->setLayout('default');
				$view->display();	
			}
			else{
				$this->setRedirect(JRoute::_('index.php?option=com_actinmap'));
			}		
		}

	}
?>